#!/bin/bash

if [[ "${*}" == *"machineType"* ]]; then
  cat <<EOF
[
  {
    "config": {
      "machineType": "e2-standard-4"
    },
    "initialNodeCount": 4,
    "name": "default-pool"
  },
  {
    "config": {
      "machineType": "e2-medium-1"
    },
    "initialNodeCount": 1,
    "name": "nondefault-pool"
  }
]
EOF
  exit 0
fi
if [[ "${*}" == *"get-credentials"* ]]; then
  echo "this_should_pass"
  echo "${*}" >| "${KUBECONFIG}"
  exit 0
fi
if [[ "${*}" == *"auth list"* ]]; then
  if [[ "${*}" == *"sa"* ]]; then
    echo "account@project.iam.gserviceaccount.com"
    exit 0
  fi
  if [[ "${*}" == *"notloggedin"* ]]; then
    exit 1
  fi
  echo "user@domain"
  exit 0
fi
if [[ "${*}" == *"this_should_fail"* ]]; then
  exit 1
fi

if [[ "${*}" == *"get-iam-policy"*"owner_this_should_pass"* ]]; then
  echo roles/owner
  exit 0
fi

if [[ "${*}" == *"get-iam-policy"*"this_should_pass"* ]]; then
  cat <<EOF
roles/servicemanagement.admin
roles/serviceusage.serviceUsageAdmin
roles/meshconfig.admin
roles/compute.admin
roles/container.admin
roles/resourcemanager.projectIamAdmin
roles/iam.serviceAccountAdmin
roles/iam.serviceAccountKeyAdmin
roles/gkehub.admin
roles/privateca.admin
EOF
exit 0
fi

if [[ "${*}" == *"this_should_pass"*"resourceLabel"* ]]; then
  echo 'mesh_id=proj-this_should_pass'
  exit 0
fi

if [[ "${*}" == *"describe"*"this_should_pass"*"json"* ]]; then
cat <<EOF
{
  "loggingService": "logging.googleapis.com/kubernetes",
  "monitoringService": "monitoring.googleapis.com/kubernetes",
  "workloadIdentityConfig": "definitely_enabled"
}
EOF
  exit 0
fi

if [[ "${*}" == *"services list --enabled"*"this_should_pass" ]]; then
  cat <<EOF
container.googleapis.com
compute.googleapis.com
monitoring.googleapis.com
logging.googleapis.com
cloudtrace.googleapis.com
meshca.googleapis.com
meshtelemetry.googleapis.com
stackdriver.googleapis.com
meshconfig.googleapis.com
iamcredentials.googleapis.com
gkeconnect.googleapis.com
gkehub.googleapis.com
cloudresourcemanager.googleapis.com
privateca.googleapis.com
EOF
exit 0
fi
if [[ "${*}" == *"this_should_pass"* ]]; then
  echo "this_should_pass"
  exit 0
fi
if [[ "${*}" == *"core/account"* ]]; then
  echo "this_should_pass"
  exit 0
fi

exit 1
